//
//  LGPatientDiagnoseBtn.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/2/20.
//

#import "LGSelectItemButton.h"

@implementation LGSelectItemButton

+(instancetype)buttonWithTitle:(NSString *)title content:(NSString *)content{
    LGSelectItemButton *button = [[LGSelectItemButton alloc]init];
    button.contentLabel.text = title;
    button.tipLabel.text = content;
    CGFloat offset = (content.length>0)?-8:0;
    [button.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(button).offset(offset);
    }];
    button.selected = NO;
    return button;
}

-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if(selected == YES){
        self.contentLabel.textColor = [UIColor colorWithString:@"#5E8EF5"];
        self.tipLabel.textColor = [UIColor colorWithString:@"#5E8EF5"];
        self.backgroundColor = [UIColor colorWithString:@"#E5F1FF"];
        self.layer.borderColor = [UIColor colorWithString:@"#5E8EF5"].CGColor;
    }else{
        self.contentLabel.textColor = [UIColor colorWithString:@"#282828"];
        self.tipLabel.textColor = [UIColor colorWithString:@"#AAAAAA"];
        self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        self.layer.borderColor = [UIColor colorWithString:@"#D9D9D9"].CGColor;
    }
   
}

#pragma mark
#pragma mark ====> 创建控件
-(instancetype)init{
    self = [super init];
    if(self){
        self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        self.layer.borderColor = [UIColor colorWithString:@"#EEEEEE"].CGColor;
        self.layer.borderWidth = 1;
        self.layer.cornerRadius = 2;
        [self addSubview:self.contentLabel];
        [self addSubview:self.tipLabel];
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(viewPix(2));
            make.right.equalTo(self).offset(-viewPix(2));
            make.centerY.equalTo(self).offset(0);
        }];
        [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentLabel);
            make.top.equalTo(self.contentLabel.mas_bottom).offset(3);
        }];
    }
    return self;
}
-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:2];
    }
    return _contentLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"" colorString:@"#AAAAAA" textFont:LGFont(10) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _tipLabel;
}
@end
